<template>
  <article class="page">
    <headerbar>评价管理</headerbar>
    <section class="frame-content-sub no-bg">

      <section class="">
        <ul class="tab" v-if="false">
          <li @click="findPjOfGr()" :class="{'active':tableIndex===0}"><span>个人</span></li>
          <li @click="organizer()" :class="{'active':tableIndex===1}"><span>主办单位</span></li>
        </ul>

        <section id="personal" class="list-wenda d-scroll mui-active" v-if="tableIndex === 0">
            <cube-scroll
              ref="scroll"
              :options="options"
              @pulling-up="onPullingUp"
            >
              <div v-for="item in list" class="item block" @click="goStudentPjList(item)">
                <div class="text-wrap">
                  <div class="title"><span>培训班：{{item.className}}</span> <span class="status color-tip"></span></div>
                  <div class="tip"><span class="one">主办单位：{{item.deptname}}</span></div>
                  <div class="tip" v-if="item.institutionsName"><span class="one">培训机构：{{item.institutionsName}}</span></div>
                  <div class="tip" v-if="item.deptname && item.institutionsName">
                    <span class="one">{{item.type==='0'?'未评价':'已评价'}}</span>
                    <div v-if="item.type==='0' && item.classType" @click="detail(item)" class="btn">评价</div>
                    <div v-if="item.type==='1'"  class=""></div>
                  </div>
                </div>
              </div>
              <div class="text-center no-data" v-if="list.length===0">
                <div class="pdv-5"></div>
                <div class="pdv-5"></div>
                <img src="../../../../static/images/no_data.png" alt="">
                <p>暂无数据</p>
              </div>
            </cube-scroll>
        </section>
        <section id="personals" class="list-wenda d-scroll mui-active" v-if="tableIndex === 1">
            <cube-scroll
              ref="scroll"
              :options="zbdwOptions"
              @pulling-up="zbdwPnPullingUp"
            >
              <div v-for="item in zbdwList" class="item block" @click="goStudentList(item)">
                <div class="text-wrap">
                  <div class="title"><span>培训班：{{item.className}}</span> <span class="status color-tip"></span></div>
                  <div class="tip"><span class="one">主办单位：{{item.deptname}}</span></div>
                  <div class="tip" v-if="item.institutionsName"><span class="one">培训机构：{{item.institutionsName}}</span></div>
                  <div class="tip" v-if="item.deptname && item.institutionsName">
                    <span class="one">{{item.sfpj==='0'?'未评价':'已评价'}}</span>
                    <div v-if="item.type==='5' && !item.zjspzt && item.sfzc === '1' && item.sfpj === '0'" @click="zbdwDetail(item)" class="btn">评价</div>
                    <div v-if="item.type!=='5'"  class=""></div>
                  </div>
                </div>
              </div>
              <div class="text-center no-data" v-if="zbdwList.length===0">
                <div class="pdv-5"></div>
                <div class="pdv-5"></div>
                <img src="../../../../static/images/no_data.png" alt="">
                <p>暂无数据</p>
              </div>
            </cube-scroll>
        </section>

      </section>

    </section>
  </article>
</template>

<script>
  export default {
    name: 'appraiseManage',
    data () {
      return {
        routeName: '1',
        pageIndex: 1,
        pageSize: 10,
        zbdwPageIndex: 1,
        zbdwPageSize: 10,
        list: [],
        zbdwList: [],
        options: {
          pullUpLoad: true,
          scrollbar: false
        },
        zbdwOptions: {
          pullUpLoad: true,
          scrollbar: false
        },
        tableIndex: 0,
        userInfo: this.$store.state.userInfo
      }
    },
    created () {
      let flag = false
      // 登录信息中MainDimId CanGroups 中维度为9  为主办单位, 其它为普通党员
      this.userInfo.canGroups.map((v) => {
        if (v.dimId === '9') {
          flag = true
        }
      })
      if (flag) {
        this.organizer()
      } else {
        this.findPjOfGr()
      }
    },
    methods: {
      clickNav (index) {
        if (this.$route.query.index !== index) {
          this.$router.replace({path: this.$route.name, query: {index: index}})
        }
        this.routeName = index
        this.pageIndex = 1
        this.list = []
        this[this.fetchNames[index]]()
      },
      detail (item) {
        this.$store.state.appraiseDetail = item
        this.$router.push({path: '/appraiseManageDetail', query: {id: item.id}})
      },
      zbdwDetail (item) {
        this.$store.state.appraiseDetail = item
        this.$router.push({path: '/zbdwAppraiseManageDetail', query: {id: item.id}})
      },
      findPjOfGr () {
        this.pageIndex = 1
        this.tableIndex = 0
        this.list = []
        let params = {
          'className': '',
          'institutionsName': '',
          'type': '',
          'userId': this.userInfo.id,
          'zbdwName': '',
          'limit': this.pageSize,
          'page': this.pageIndex
        }
        return this.fetchService.findPjOfGr(params).then(res => {
          console.log(res)
          if (res.code !== 0) {
            return this.tools.tip(res.message || '获取数据失败')
          }
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          this.list = this.list.concat(res.data)
          return res
        })
      },
      onPullingUp () {
        this.pageIndex ++
        this.findPjOfGr().then(res => {
          if (res.data.length === 0) {
            this.tools.tip('已无更多数据')
          }
          setTimeout(() => {
            this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          })
        })
      },
      zbdwPnPullingUp () {
        this.zbdwPageIndex ++
        this.organizer().then(res => {
          if (res.data.length === 0) {
            this.tools.tip('已无更多数据')
          }
          setTimeout(() => {
            this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          })
        })
      },
      organizer () {
        this.zbdwPageIndex = 1
        this.tableIndex = 1
        this.zbdwList = []
        let params = {
          'limit': this.zbdwPageSize,
          'page': this.zbdwPageIndex
        }
        return this.fetchService.findZbdwPjOfApp(params).then(res => {
          console.log(res)
          if (res.code !== 0) {
            return this.tools.tip(res.message || '获取数据失败')
          }
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          this.zbdwList = this.zbdwList.concat(res.data)
          return res
        })
      },
      goStudentList (data) {
        if (data.userContactList) {
          this.$store.state.appraiseManageStudentList = data.userContactList
        } else {
          this.$store.state.appraiseManageStudentList = []
        }
        this.$router.push({path: `/appraiseManageStudentList`})
      },
      goStudentPjList (data) {
        if (data.pjList) {
          this.$store.state.appraiseManageStudentPjList = data.pjList
        } else {
          this.$store.state.appraiseManageStudentPjList = []
        }
        this.$router.push({path: `/appraiseManageStudentPjList`})
      }
    }
  }
</script>

<style scoped>

</style>
